package com.monkey.core.plugin.code.tpl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.monkey.core.plugin.dto.MonkeyDto;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

/**
 * Project  : monkey
 * Author   : Wu Tian Qiang
 * Date     : 2016/10/10
 */
public class TreeListTemplateGenerator extends SimpleCodeTemplateGeneratorImpl {

    @Override
    protected String getServiceImplTemplate() {
        return "templates/treelist/serviceImpl.java.vm";
    }

    @Override
    protected String getServiceTemplate() {
        return "templates/treelist/service.java.vm";
    }

    @Override
    protected String getControllerTemplate() {
        return "templates/treelist/controller.java.vm";
    }

    @Override
    protected String getDomainTemplate() {
        return "templates/treelist/domain.java.vm";
    }

    @Override
    protected String getWindowControllerTemplate() {
        return "templates/treelist/view/window.js.vm";
    }

    @Override
    protected String getViewModelControllerTemplate() {
        return "templates/treelist/view/viewmodel.js.vm";
    }

    @Override
    protected String getModelControllerTemplate() {
        return "templates/treelist/view/model.js.vm";
    }

    @Override
    protected String getStoreControllerTemplate() {
        return "templates/treelist/view/store.js.vm";
    }

    @Override
    protected String getViewTemplate() {
        return "templates/treelist/view/view.js.vm";
    }

    @Override
    protected String getViewControllerTemplate() {
        return "templates/treelist/view/controller.js.vm";
    }

    @Override
    protected Map<String, Object> prepareCustomParams(MonkeyDto monkeyDto) throws UnsupportedEncodingException {
        Map<String, Object> params = new HashMap<>();
        JSONObject customValues = JSON.parseObject(URLDecoder.decode(monkeyDto.getString("customValues"), "UTF-8"));
        params.put("title", customValues.getString("title"));
        return params;
    }

}
